# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=mailman-web
pkgver=0.0.6
_commit=fd605ed417c88e078c5c6e35e97b50b3e28efc73  # refs/tags/0.0.6
pkgrel=2
pkgdesc="The web interface for Mailman 3"
arch=(any)
url="https://gitlab.com/mailman/mailman-web"
license=(GPL3)
depends=(hyperkitty postorius python-django python-whoosh)
makedepends=(git python-build python-installer python-setuptools-scm python-wheel)
optdepends=(
  'mailman3: for interacting with a local mailman instance'
  'uwsgi-plugin-python: for running inside uwsgi'
)
backup=(
  etc/webapps/$pkgname/settings.py
  etc/webapps/$pkgname/urls.py
)
options=()
source=(
  git+https://gitlab.com/mailman/mailman-web#tag=$_commit?signed
  $pkgname-qcluster.service
  settings.py
  $pkgname.sysusers
  $pkgname.tmpfiles
  $pkgname.uwsgi
  $pkgname-0.0.5-fhs.patch
)
sha512sums=('SKIP'
            '5440c170f50cbc4c95e0cf4c9d2c8a03759e0d13c2f9c604a6eaedfde9abcc4ae6cc9845d53d58cd4ee06373bab166f3115a59ebac3b77fe1d33ab7054c7c5d7'
            'cf255da4028a36a21473166a44c4a104b58ed824b81a08548bd89a861f9684bf89d166c4827b8dd5d9e516a9b0a30bbf26733f9a7e3f0d85f1c5c29f3929a3db'
            '4044b2500dc63ec1cea829d0189428de590755006c38d6f82e5a51af8935409a1ea5a5fb1f676d2331ceb59383cf79730837427eff32ad82f900068684aa3b45'
            '07aa2af5f72dccdfe32f3f220d798e5e6d57ed6875566e33ad610a05a063861a84aa6bb6d4c9a172711862855e7eae68a19fd6dcd098893f4a365579bd29cf57'
            '744a0f0af9c5683b50bf43816262917edeb47e954aba1ac7c9d831eddf3c5e63e307811e35161ac3a717b08f7d9c3dface0a2703a7c2a0f6d3a9882ce445109f'
            '311b968255435f20ee3c9d4c88e7c4f122b93b6fef8b586896e5cd3bf63e95fae1b4a770cacb3e6eb35859b5a69f26f98c3cd9ca44fcfb509ef676556f2fb67e')
b2sums=('SKIP'
        '48d65925bbbe4f17c1d4a656eb533621904fbffee06ff0ce09fbc9ad69cd947269998f31a9a172645d9389d98caf8395e4a3d9fbaafeedbf52b774725d446e29'
        '40c2583cf72597fbcdfeecabb8aa10cb2fe1e5f9b60669bdc933e4884899325f70ba4ab9f27dc702aacf26f0b0de400b26245c7770a9b3e8cc0b0641478028d6'
        'c57e70b949947ce3d30053886620221346d87416034cd004dcd91107e55a0123fb37a6c68796168ddabaab467b0f77dd8292e650df05e2e1eed0ec4d63becc2b'
        '80ca9c95c9bb3ce42bd4e3efbea59bc6cbbdabd35c504ee5c7414b8c657d863119921577fb618e0709631d05704d24698a2575f12aed81cf1cf16cd8ce116ed9'
        '7f39c6752f54048e1268c94010fa2fbdc6cc7db0c931c616469068ba835330b9cb8ec183978f2047fd8e0aff88b25de7437cbb112dbdad25f795e25f2419f809'
        '7c176a0ae2ea3cb266b08e821c971ff00d39c2cb3de2b93de6b69e4c38e4647b1b42df468bb0d8ac72f02b069d34969d29e586093f7183a19371d83cabdd3fc7')
validpgpkeys=('541EA0448453394FF77A0ECC9D9B2BA061D0A67C') # Abhilash Raj <raj.abhilash1@gmail.com>

pkgver() {
  cd $pkgname
  git describe | sed 's/\([^-]*-g\)/r\1/;s/v//g;s/-/./g'
}

prepare() {
  # set FHS and packaging compliant default locations
  patch -Np1 -d $pkgname -i ../$pkgname-0.0.5-fhs.patch
}

build() {
  cd $pkgname
  python -m build --wheel --no-isolation
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname
  python -m installer --destdir="$pkgdir" dist/*.whl

  # config
  install -vDm 640 ../settings.py "$pkgdir/etc/webapps/$pkgname/settings.py"
  install -vDm 640 mailman_web/urls.py "$pkgdir/etc/webapps/$pkgname/urls.py"
  ln -sfv /etc/webapps/$pkgname/urls.py "$pkgdir/$site_packages/${pkgname/-/_}/urls.py"

  install -vdm 750 "$pkgdir/var/lib/$pkgname/data/"
  install -vdm 755 "$pkgdir/var/lib/$pkgname/static/"
  install -vdm 750 "$pkgdir/var/log/$pkgname/"

  install -vDm 644 ../$pkgname.uwsgi "$pkgdir/etc/uwsgi/$pkgname.ini"
  install -vDm 644 ../$pkgname-qcluster.service -t "$pkgdir/usr/lib/systemd/system/"
  install -vDm 644 ../$pkgname.tmpfiles "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
  install -vDm 644 ../$pkgname.sysusers "$pkgdir/usr/lib/sysusers.d/$pkgname.conf"
  install -vDm 644 README.rst -t "$pkgdir/usr/share/doc/$pkgname/"
}
